const isDev = process.env.NODE_ENV === 'development'
const pkgName = process.env.VUE_APP_MODULE = process.env.npm_package_name
const publicPath = isDev ? '/' : `/${pkgName}/`


module.exports = {
  publicPath,
  devServer: {
    port: 8081,
  },
  chainWebpack: (config) => {
    if (!isDev) {
      const rules = ['images', 'fonts']
      rules.forEach(rule => {
        config.module.rule(rule).use('url-loader').tap(options => {
          options.fallback = {
            loader: 'file-loader',
            options: {
              name: `img/[name].[hash].[ext]`,
              publicPath
            }
          }
          return options
        })
      })

      config.module.rule('svg').use('file-loader').tap(options => {
        options.name = `img/[name].[hash].[ext]`
        options.publicPath = publicPath
        return options
      })
    }
  },
}
